import { isEmpty, isNotEmptyObject, isObject } from 'class-validator';

export function pickConditions<T>(conditions: Partial<T>): Partial<T> {
  for (const key in Reflect.ownKeys(conditions as any)) {
    if (isObject(conditions[key])) {
      conditions[key] = pickConditions(conditions[key]) as any;
    }
    if (isEmpty(conditions[key]) || !isNotEmptyObject(conditions)) {
      delete conditions[key];
    }
  }
  return conditions;
}
